package com.xyq.fs.task;

import java.nio.file.Path;

import com.xyq.fs.base.MyDirectoryS;
import com.xyq.fs.constants.IndexStringConstants;
import com.xyq.fs.index.IndexFileInf;
import com.xyq.fs.views.WindwosA;

public class MyTask extends AfAsyncTask {

	private IndexFileInf iff;

	private Path path;
	private int tempnum;
	private boolean needUpdateDoc;

	private boolean needUpdateUi;

	public IndexFileInf getIff() {
		return iff;
	}

	public void setIff(IndexFileInf iff) {
		this.iff = iff;
	}

	public Path getPath() {
		return path;
	}

	public void setPath(Path path) {
		this.path = path;
	}

	public int getTempnum() {
		return tempnum;
	}

	public void setTempnum(int tempnum) {
		this.tempnum = tempnum;
	}

	public boolean isNeedUpdateUi() {
		return needUpdateUi;
	}

	public void setNeedUpdateUi(boolean needUpdateUi) {

		super.setNeedUpdateUi(needUpdateUi);
		this.needUpdateUi = needUpdateUi;
	}

	public boolean isNeedUpdateDoc() {
		return needUpdateDoc;
	}

	public void setNeedUpdateDoc(boolean needUpdateDoc) {
		this.needUpdateDoc = needUpdateDoc;
	}

	public MyTask(IndexFileInf iff, Path path, int tempnum, boolean needUpdateUi,boolean needUpateDoc) {

		super(needUpdateUi);
		this.needUpdateUi = needUpdateUi;
		this.iff = iff;
		this.path = path;
		this.tempnum = tempnum;
		this.needUpdateDoc = needUpateDoc;

	}

	@Override
	protected void doInBackground() throws Exception {

		iff.indexFile(path, null);
	}

	@Override
	protected void onPostExecute() {

		WindwosA.tsB.setText(IndexStringConstants.YSM + tempnum);
		if (needUpdateDoc) {
			new Thread(() -> {
				MyDirectoryS.commit();
				MyDirectoryS.updateReaderAndSearcher();
				
			}).start();
		}
	}
}
